import { nextTick } from "vue";
import router from "@/router";
import { store } from "@/store";

/**
 * 设置浏览器标题国际化
 * @method const title = useTitle(); ==> title()
 */
function useTitle(){
	return function(text:string=''){
		nextTick(() => {
			let webTitle = '';
			let globalTitle: string = store.state.themeConfig.themeConfig.globalTitle;
			router.currentRoute.value.path === '/login'
				? (webTitle = router.currentRoute.value.meta.title as any)
				: (webTitle = router.currentRoute.value.meta.title as any);
			if(text){
				document.title = text?`${text} - ${globalTitle}` : globalTitle;
			}else{
				document.title = webTitle?`${webTitle} - ${globalTitle}` : globalTitle;
			}
		});
	}
}
//i18n.global.t()
export default useTitle;